import React, { Component } from 'react';
import { nanoid } from 'nanoid';
import PubSub from 'pubsub-js';
import './index.css'; 

export default class Header extends Component {
  handleKeyup = (event) => {
    if (event.keyCode !== 13) return
    // this.props.addTodo({id: nanoid(), name: event.target.value, done: false})
    PubSub.publish('shucheng', {id: nanoid(), name: event.target.value, done: false})
  }
  
  render() {
    return (
      <div className="todo-header">
        <input onKeyUp={this.handleKeyup} type="text" placeholder="请输入你的任务名称，按回车键确认"/>
      </div>
    )
  }
}
